﻿@using Website.CRUDServices
@using Website.Models.Styling
@using Location = Website.Models.Domain.Location
@model Website.Models.ViewModels.ListView<Activity>
@{
    this.ViewBag.Title = "Netværk";
    this.Layout = "~/Views/_Shared/_Layout.cshtml";
    var users = this.ViewData["Users"] as List<User>;
    var criteriaLocation = this.ViewData["CriteriaLocation"] as Guid?;
    var locations = this.ViewData["Locations"] as List<Location>;
    List<Profile> profiles = this.ViewData["Profiles"] as List<Profile> ?? new List<Profile>();
    List<Guid> criteriaAttendees = this.ViewData["CriteriaProfiles"] as List<Guid> ?? new List<Guid>();
    List<Guid> criteriaSupportForBusinessAttendance = this.ViewData["CriteriaSupportForBusinessAttendance"] as List<Guid> ?? new List<Guid>();
    DefaultSearchFields defaultFields = this.ViewData["DefaultFields"] as DefaultSearchFields ?? new DefaultSearchFields();
    List<Guid> criteriaPresentations = this.ViewData["CriteriaPresentations"] as List<Guid> ?? new List<Guid>();
    List<Presentation> presentations = this.ViewData["Presentations"] as List<Presentation> ?? new List<Presentation>();
    var criteriaOrganizer = this.ViewData["CriteriaOrganizer"] as Guid? ?? null;
    var criteriaNetworkType = this.ViewData["CriteriaNetworkType"] as string ?? string.Empty;
    var networkTypes = new List<dynamic>()
    {
        new { NType = "IsNetworkingEvent", Name = "Netværksmøde"},
        new { NType = "IsConferenceEvent", Name = "Konference"},
        new { NType = "IsDelegationTravel", Name = "Delegationsrejse"},
        new { NType = "IsProductLaunch", Name = "Produkt lancering"}
    };
    
   
}
<h2>Søgeresultat - @ViewBag.Title</h2>

<fieldset class="searchCriterias">
    <legend>Søgning</legend>
    <table>    
        <tr>
            <td>Type:</td><td>@ViewBag.Title</td>
        </tr>
        <tr><td>Antal resultater i alt: </td><td>@Model.TotalRows</td></tr>
        @if (criteriaLocation.HasValue && criteriaLocation.Value != Guid.Empty)
        {
            <tr><td>Lokation: </td><td>@locations.Single(x => x.ID == criteriaLocation.Value).Name</td></tr>
        }
        @if (criteriaPresentations.Any())
        {
            <tr><td>Præsentationer: </td>
                <td>
                    @foreach (Presentation pres in presentations.Where(x => criteriaPresentations.Contains(x.ID)).OrderBy(x => x.Name))
                    {
                        @pres.Name
                        <br />
                    }
                </td>
            </tr>
        }
        @if (criteriaAttendees.Any())
        {
            <tr>
                <td>Deltagere:</td>
                <td>
                    @foreach (Profile profile in profiles.Where(x => criteriaAttendees.Contains(x.ID)).OrderBy(x => x.Name))
                    {
                        @profile.Name
                        <br />
                    }
                </td>
            </tr>
        }
        @if (criteriaSupportForBusinessAttendance.Any())
        {
            <tr>
                <td>Understøttelse af virksomhedsdeltagelse:</td>
                <td>
                    @foreach (Profile profile in profiles.Where(x => criteriaSupportForBusinessAttendance.Contains(x.ID)).OrderBy(x => x.Name))
                    {
                        @profile.Name
                        <br />
                    }
                </td>
            </tr>
        }
        @if (criteriaOrganizer.HasValue && criteriaOrganizer.Value != Guid.Empty)
        {
            <tr>
                <td>Arrangør:</td>
                <td>
                    @if (profiles.Any(x => x.ID == criteriaOrganizer.Value))
                    {
                        @profiles.Single(x => x.ID == criteriaOrganizer.Value).Name
                    }
                </td>
            </tr>
        }
        @if (criteriaNetworkType != null && networkTypes.Any(x => x.NType == criteriaNetworkType))
        {
            <tr>
                <td>Netværks type:</td>
                <td>
                    @networkTypes.First(x => x.NType == criteriaNetworkType).Name
                </td>
            </tr>
        }
   
        @Html.Partial("~/Views/Reports/_SearchDefaultFieldsParametersTableTR.cshtml", defaultFields)

    </table>
</fieldset>





<table class="tableView tableWithOnlyLastChild">
    <tr>
        @foreach (TableViewHeaderItem item in this.Model.Header.Items)
        {
            <td>
                @Html.Partial("~/Views/_Shared/TableViewHeader.cshtml", item)
            </td>
        }
        <td></td>
    </tr>
     @if (this.Model != null)
    {
        foreach (Activity act in this.Model.List)
        {

        <tr>
            <td>@string.Format("{0:dd-MM-yyyy}", act.TimeOfActivity)</td>
            <td>
                @if(act.NA.IsConferenceEvent.HasValue && act.NA.IsConferenceEvent.Value){
                    <label>Konference</label>
                }
                else if (act.NA.IsDelegationTravel.HasValue && act.NA.IsDelegationTravel.Value)
                {
                    <label>Delegationsrejse</label>
                }
                else if (act.NA.IsNetworkingEvent.HasValue && act.NA.IsNetworkingEvent.Value)
                {
                    <label>Netværksmøde</label>
                }
                else if (act.NA.IsProductLaunch.HasValue && act.NA.IsProductLaunch.Value)
                {
                    <label>Produkt lancering</label>
                }
            </td>
            <td>@act.NA.ProductType</td>
            <td>
                @if (act.NA.Booth.HasValue && act.NA.Booth.Value)
                {
                    <label>Stand</label>
                }
                @if (act.NA.Attendance.HasValue && act.NA.Attendance.Value)
                {
                    <label>Deltagelse</label>
                }
                @if (act.NA.Organizer.HasValue && act.NA.Organizer.Value)
                {
                    <label>Organisør</label>
                }
            </td>
            <td><a href="@Url.Action("ViewNetwork", "Networking", new { Id = act.ID })" target="@act.ID.ToString()">
                        <img src="@Url.Content("~/Content/ButtonIcons/notepad_blue.png")" alt="Link"/></a></td>
        </tr>
        }
    }
    <tr><td colspan="@(1+ Model.Header.Items.Count())"></td></tr>
</table>